param([xml]$xmlDoc)
begin
{
	function FormatXML([xml]$xmlDoc)
	{
		$memoryStream = New-Object System.IO.MemoryStream 
		
		$xmlWriterSettings = New-Object System.Xml.XmlWriterSettings
		$xmlWriterSettings.Encoding = New-Object System.Text.UTF8Encoding
		$xmlWriterSettings.ConformanceLevel =  [System.Xml.ConformanceLevel]::Document
		$xmlWriterSettings.Indent = $true
		
		$xmlWriter = [System.Xml.XmlWriter]::Create($memoryStream,$xmlWriterSettings)
		$xmlDoc.Save($xmlWriter)
		$xmlWriter.Flush()
		$xmlWriter.Close()
		$memoryStream.Close()
		([System.Text.Encoding]::UTF8.GetString($memoryStream.GetBuffer())).Trim(0)
	}
	
	if ($xmlDoc -ne $null)
	{
		FormatXML $xmlDoc
	}
}

process
{
	if($_ -ne $null)
	{
		FormatXML $_
	}
}
